package ccm.component.menu;

import ccm.common.Buffer;
import ccm.component.override.JButton;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class FunctionMenuItemJPanel extends SingleMenuItem implements ActionListener
{
    final protected JButton sendJButton;

    protected FunctionMenuItemJPanel(DelegateSenderInterface sender,String saveArgPrefix,int dataIndex,boolean canModify,ScnsType type,int page,String name)
    {
        super(sender,null,saveArgPrefix,dataIndex,canModify,type,page,name);
        nameJLabel.setPreferredSize(new Dimension(nameJLabel.getPreferredSize().width*2,nameJLabel.getPreferredSize().height));
        sendJButton=new JButton("执行");
        add(sendJButton);
        sendJButton.addActionListener(this);
        loadConfig();
        setCanModify(false);
    }


    @Override
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource()==sendJButton)
        {
            needSendValueFlag=true;
        }
    }

    @Override
    public void sendValueToDevice()
    {
        int start=0;
        byte[] buf=new byte[64];
        start=Buffer.setUint16(buf,start,dataIndex);
        start=Buffer.setUint8(buf,start,type.ordinal());
        addTailAndSend(buf,start,0X20);
        needSendValueFlag=false;
    }

    @Override
    public String toString()
    {
        return nameJLabel.getText();
    }
}
